package de.sendorian.db;

import java.util.List;


public interface Repository<T> {

    public <E> E update(E entity);


    public <E> E save(E entity);


    public void saveOrUpdate(Object entity);


    public void delete(Object entity);


    public int deleteById(Object id);


    public int deleteByAttribute(String attribute, Object value);


    /**
     * Loads the entity with the given ID from the database. The Type of the
     * entity is set through the type parameter (and can be of any entity
     * type!).
     * 
     * @return The entity, null if not found.
     */
    public <E> E findById(Class<E> type, Object key);


    /**
     * Loads the entity with the given ID from the database. The Type of the
     * entity is set through the type of this DAO.
     * 
     * @return The entity, null if not found.
     */
    public T findById(Object id);


    public boolean existsById(Object key);


    public List<T> findByAttribute(String attribute, Object value);


    public T findByUniqueAttribute(String attribute, Object value);


    public void deleteAll();


    public List<T> findAll();


    /**
     * Searches for entities for which the given String property matches the
     * given valuePattern (like, ignore case).
     * 
     */
    public List<T> search(String attribute, String valuePattern);
    
    
    public void shutdownDatabase();

}
